// RedJey Graphics User Interface Library for J2ME Platform.
// Copyright (C) 2008 Yevgen Krapiva
//
// This library is free software; you can redistribute
// it and/or modify it under the terms of the
// GNU Lesser General Public License as published
// by the Free Software Foundation; either version 3.0
// of the License, or any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//

package com.incrediblesoft.redjey.backgrounds;

/**
 * @author Yevgen Krapiva<br>
 *         Homepage: http://code.google.com/p/redjey/<br>
 *         Feedback: ykrapiva@gmail.com<br>
 *         Copyright (C) 2008 Yevgen Krapiva<br>
 */

import com.incrediblesoft.redjey.backgrounds.AbstractBackground;

import javax.microedition.lcdui.Graphics;
import java.util.Hashtable;

public class SimpleBackground extends AbstractBackground
{
    private int color = 0;
    private int arcWidth, arcHeight;

    public SimpleBackground(int color)
    {
        this(color, 0, 0);
    }

    public SimpleBackground(int color, int arcWidth, int arcHeight)
    {
        super();
        this.color = color;
        this.arcWidth = arcWidth;
        this.arcHeight = arcHeight;
    }

    public SimpleBackground(Hashtable styleDesc)
    {
        super(styleDesc);
        String str = (String) styleDesc.get("color");
        if (str != null) color = (int) Long.parseLong(str, 16);
        str = (String) styleDesc.get("arcWidth");
        if (str != null) arcWidth  = Integer.parseInt(str);
        str = (String) styleDesc.get("arcHeight");
        if (str != null) arcHeight  = Integer.parseInt(str);
    }

    public void paint(Graphics g, int x, int y, int width, int height)
    {
        g.setColor(this.color);
        if (arcWidth > 0 || arcHeight > 0)
            g.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
        else
            g.fillRect(x, y, width, height);
    }

    public AbstractBackground clone()
    {
        SimpleBackground newBackground = new SimpleBackground(color, arcWidth, arcHeight);
        return newBackground;
    }

}
